<%@page import="java.util.Calendar"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Collection"%>
<%@page import="orm.Users"%>
<%@page import="orm.Items"%>
<%@page import="orm.Transactions"%>
<%@page import="hibernatelogic.HibItems"%>
<%@page import="hibernatelogic.HibUsers"%>
<%@page import="hibernatelogic.HibTransactions"%>
<%@page import="java.util.GregorianCalendar"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    
<%
	HttpSession sess = request.getSession();

	if(sess.isNew()) {
		response.sendRedirect("/my-pet-project-0/Login.jsp");
	} else {
%>
<%
		if(((String) sess.getAttribute("UserRole")).equals("2")) {
%>

<%
	HibTransactions hibTransactions = new HibTransactions();
	HibUsers hibUsers = new HibUsers();
	HibItems hibItems = new HibItems();
	Transactions transaction = new Transactions();
	Items item = new Items();
	Users user = new Users();
	Collection col = null;
	Iterator it = null;
	col = hibTransactions.getNotApprovedTransactions();
	ArrayList tmpCol = (ArrayList) col;
	it = tmpCol.iterator();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Approve transactions</title>
</head>
<body>
	<a href="/my-pet-project-0/Login.jsp">Logout</a>
	<a href="/my-pet-project-0/ManagerStartPage.jsp">Back</a>
	<br>
	<br>
	<center>Choose transactions to be approved/disapproved</center>
	<br>
	<br>
	<center>
	<form action="approve-transaction-servlet" method="post">
		<select name="transaction">
			<%
				while(it.hasNext()){
					transaction = (Transactions) it.next();
					user = (Users) hibUsers.getUserByID(transaction.getUsers());
					item = (Items) hibItems.getItemByID(transaction.getItems());
			%>
			<option value=<%=transaction.getTr_id()%>><%=user.getName()%> - <%=item.getItem_name()%> - <%=item.getItem_price()%>$ - <%=transaction.getQuantity()%>pcs. - <%=transaction.getSal_time().get(Calendar.YEAR)%>/<%=(transaction.getSal_time().get(Calendar.MONTH) + 1)%>/<%=transaction.getSal_time().get(Calendar.DAY_OF_MONTH)%>
			<%
				}
			%>
		</select>
		<br>
		<br>
		<input type="radio" name="approve" value="1" checked>Approve
		<input type="radio" name="approve" value="0">Disapprove
		<br><br>
		<input type="submit" value="Run">
	</form>
	</center>
</body>
</html>
<%
				} else {
%>
<%
	response.sendError(response.SC_FORBIDDEN,
					"Not permitted to enter as MANAGER");
%>
<%
	}
	}
%>